import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;

public class Share extends Setup {
	static int bUserID;
	static int bStop;
	static PrintWriter pw;

	static void checkArgs(String[] args) {
		if (args.length > 2) {
			bUserID = Integer.valueOf(args[0]);
			bStop = Integer.valueOf(args[1]);
			if (args[2].contains("tes")) {
				FILE_PATH_USER_B = "../track1/testIdx1.txt" + ".ser";
			} else {
				FILE_PATH_USER_B = "../track1/validationIdx1.txt" + ".ser";
			}
		} else {
			System.out.println("Wrong number of arguments! Try:");
			System.out.println("bStart bStop tes");
			System.exit(0);
		}
	}

	static void initialize(String HOME) {
		System.out.println("Home: " + HOME);
		makePw(HOME);
		setup();
	}

	static void makePw(String HOME) {
		String VAL = "val";
		if (FILE_PATH_USER_B.contains("tes")) {
			VAL = "tes";
		}

		String start = String.format("%08d", bUserID);
		String stop = String.format("%08d", bStop);
		String path = HOME + "/" + VAL + "/";

		File folder = new File(path);
		if (!folder.exists()) {
			folder.mkdirs();
		}

		String FILE_LOCATION = path + start + "-" + stop + ".csv";

		try {
			pw = new PrintWriter(FILE_LOCATION);
		} catch (FileNotFoundException ex) {
			ex.printStackTrace();
		}

		System.out.println("writing file: ");
		System.out.println(FILE_LOCATION);
	}

	static void println(String s) {
		if (bUserID % 1000 == 0) {
			System.out.print(s + "\n");
		}
		pw.print(s + "\n");
	}

	static void print(String s) {
		if (bUserID % 1000 == 0) {
			System.out.print(s + ",");
		}
		pw.print(s + ",");
	}

	static void print(double d) {
		if (bUserID % 1000 == 0) {
			System.out.printf("%.0f,", d);
		}
		pw.printf("%.0f,", d);
	}

	static void println(double d) {
		if (bUserID % 1000 == 0) {
			System.out.printf("%.0f\n", d);
		}
		pw.printf("%.0f\n", d);
	}
}
